<?php

namespace App\Admin\Eloquent;

class TradeRecord extends Model
{
    protected $fillable = [
        'type', 'project_id', 'sn', 'pay_user', 'receive_user','money','remarks','created_at','pay_time','end_time',
        'card_number','status','gift','pid','user_balance','fee_money','user_fee'
      ];
      public $timestamps = false;
    /**
     * 交易类型
     *
     * @return string
     */
    public function getTypeAttribute()
    {
        switch ($this->attributes['type']) {
            case 1:
                return '分润';
            case 2:
                return '投资';
            case 3:
                return '还款';
            case 4:
                return '充值';
            case 5:
                return '提现';
            case 6:
                return '现金红包';
            case 7:
                return '投资红包';
            
            default:
                return '未知';
        }
    }

    /**
     * 交易状态
     *
     * @return string
     */
    public function getTradeStatusAttribute()
    {
        switch ($this->attributes['status']) {
            case 0:
                return "处理中";
            case 1:
                return "成功";
            
            default:
                return "失败";
        }
    }

    public function getPayeeAttribute()
    {
        if ($user = User::find($this->attributes['pay_user'])) {
            return ($user->username?:$user->phone_number)?:$user->email;
        }

        return '-';
    }

    public function getReceiverAttribute()
    {
        if ($user = User::find($this->attributes['receive_user'])) {
            return ($user->username?:$user->phone_number)?:$user->email;
        }

        return '-';
    }
}